<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PySynth &mdash; A Music Synthesizer for Python</title>
<style type="text/css">
	body { color: #008;
		background: #bbceff url(bach.png) 0 0 repeat fixed;
		font-family: TeXGyreBonum, Sabon, "Sabon LT Std", "Big Caslon", "Gentium Book Basic", "New Century Schoolbook", Times, serif;
		font-size: 12pt;
		line-height: 16pt }
	a:link    { color: #a00 }
	a:visited { color: #500 }
	a:hover   { color: #fff; background: #a00 }
	a:active  { color: #ff0 }
	h2 { font-variant:small-caps }
	pre {
		font-size: 10pt;
		line-height: 12pt
	}

.dot { font-family: SynthetiqueOTRegular;
       font-size: 52pt;
       margin:0px auto;
       padding-top: 20px;
       color: #ff0;
       text-shadow:0 0 6px #f00;
}

.download:hover { 
       background: #a00;
}

@media only screen and (min-device-width : 320px) and (max-device-width : 569px) {
       .note, .hideimg {
		display: none;
	}
	ul {
	    list-style-position: inside;
	    padding-left: 0;
	}
}

/* https://css-tricks.com/examples/hrs/ */
hr {
    border: 0;
    height: 0; /* Firefox... */
    box-shadow: 0 0 10px 1px black;
}
hr:after {  /* Not really supposed to work, but does */
    content: "\00a0";  /* Prevent margin collapse */
}

/* Generated by Font Squirrel (http://www.fontsquirrel.com) on January 8, 2011 01:09:25 PM America/New_York */

@font-face {
	font-family: 'SynthetiqueOTRegular';
	src: url('synthetique/synthetique-webfont.eot');
	src: local('☺'), url('synthetique/synthetique-webfont.woff') format('woff'), url('synthetique/synthetique-webfont.ttf') format('truetype'), url('synthetique/synthetique-webfont.svg#webfontaNBtqWD8') format('svg');
	font-weight: normal;
	font-style: normal;
}

/* Generated by Font Squirrel (http://www.fontsquirrel.com) on January 12, 2011 05:09:35 PM America/New_York */



@font-face {
	font-family: 'TeXGyreBonum';
	src: url('gyre/texgyrebonum-regular-webfont.eot');
	src: local('☺'), url('gyre/texgyrebonum-regular-webfont.woff') format('woff'), url('gyre/texgyrebonum-regular-webfont.ttf') format('truetype'), url('gyre/texgyrebonum-regular-webfont.svg#webfontwUTe3Y7O') format('svg');
	font-weight: normal;
	font-style: normal;
}

@font-face {
	font-family: 'TeXGyreBonum';
	src: url('gyre/texgyrebonum-italic-webfont.eot');
	src: local('☺'), url('gyre/texgyrebonum-italic-webfont.woff') format('woff'), url('gyre/texgyrebonum-italic-webfont.ttf') format('truetype'), url('gyre/texgyrebonum-italic-webfont.svg#webfonteSUpp3GS') format('svg');
	font-weight: normal;
	font-style: italic;
}

@font-face {
	font-family: 'TeXGyreBonum';
	src: url('gyre/texgyrebonum-bold-webfont.eot');
	src: local('☺'), url('gyre/texgyrebonum-bold-webfont.woff') format('woff'), url('gyre/texgyrebonum-bold-webfont.ttf') format('truetype'), url('gyre/texgyrebonum-bold-webfont.svg#webfont82gb6PCB') format('svg');
	font-weight: bold;
	font-style: normal;
}

@font-face {
	font-family: 'TeXGyreBonum';
	src: url('gyre/texgyrebonum-bolditalic-webfont.eot');
	src: local('☺'), url('gyre/texgyrebonum-bolditalic-webfont.woff') format('woff'), url('gyre/texgyrebonum-bolditalic-webfont.ttf') format('truetype'), url('gyre/texgyrebonum-bolditalic-webfont.svg#webfontVUd4kPiA') format('svg');
	font-weight: bold;
	font-style: italic;
}


</style>
</head>
<body bgcolor="#bbceff">
<center><div style="align: center; padding: 25px 0px 10px 0px; background: linear-gradient(#d3c7f1, #f2f692);">
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
<span class="dot">PySynth</span>
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
<img src="1f3b5.svg" width="30px" class="note">
</div></center>
<p align="center">
<a href="#d">Downloads</a> | 
<a href="#h">Changes</a> | 
<a href="#m">Synthesizer modules</a> | 
<a href="#s">Support scripts</a> | 
<a href="#u">Usage</a> | 
<a href="#l">License</a> | 
<a href="#c">Contact</a>
<div style="align: center; padding: 25px 0px 10px 0px; background: red;">
<h2>PySynth is looking for a new maintainer! Please fork the project now if you would like to adopt it!</h2>
</div>
</p></center>
<img src="clipart/ENCA025D.svg" width="60px" align="left" style="padding-right: 20px;">
<img src="clipart/JUKEB1.svg" width="200px" align="right" class="hideimg">
<p><b>PySynth</b> is a suite of simple music synthesizers and helper scripts written in <a href="http://www.python.org/">Python 3</a>. It is based on a synth script I found on the Web and then modified for my purposes. The goal is not to produce many different sounds, but to have scripts that can turn <a hreF="http://abcnotation.com/">ABC notation</a> or <a href="https://en.wikipedia.org/wiki/MIDI">MIDI</a> files into a WAV file without too much tinkering.</p>

<p>There are <a href="#m">nine PySynth variants</a> now: PySynth A, the oldest variant, only needs Python itself, and sounds somewhat like a cross between a flute and organ. PySynth B is more complex in sound and needs <a href="http://numpy.org/">NumPy</a>. It is supposed to be a little closer to a piano. No competition for Pianoteq of course, but a reasonable fit for keyboard music. PySynth E is similar, but an FM-synthesized e-piano so it sounds much brighter than B (slightly DX7 e-piano-like; I used the DX7 presets in <a href="http://smbolton.com/hexter.html">hexter</a> as a basis). PySynth S is more comparable to a guitar, banjo, or harpsichord, depending on note length and pitch. PySynth C, D, and P are subtractive synths, reminiscent of 1970s analog synthesizer voices.</p>

<p>The synthesizers are all monophonic, i.e. they can only play one note at a time.  (Although successive notes can overlap in PySynth B and S, but not A.)  However, two or more output files can be mixed together as in the case of the stereo files below.</p>

<p>If you need more powerful Python sound synthesis than PySynth offers, you might want to check out the <a href="http://ajaxsoundstudio.com/software/pyo/">Pyo</a> toolkit. To convert complex ABC files to MIDI you might want to try <a href="https://github.com/leesavide/abcmidi">abcmidi</a>. Some good Open Source  synthesizers are <a href="http://yoshimi.sourceforge.net/">Yoshimi<a/a>, <a href="http://amsynth.github.io/">amsynth</a>, and <a href="http://asb2m10.github.io/dexed/">Dexed<a/a>.</p>

<hr>

<img src="clipart/ENSS021D.svg" width="350px" align="right">
<h2><a name="e">Audio samples</a></h2>

<p>Here are some WAV output files converted to MP3 or MP4 format:</p>

<h3>Mono</h3>
<ul>

<li><b><i>Main Title</i></b> from <i>Star Trek: The Motion Picture</i> (comp. Jerry Goldsmith, arr. <a href="https://musescore.com/user/4346626/scores/3688516">eRock92</a>)  &mdash; PySynth <b>A</b> (24 tracks) and Calf Reverb
<br><img src="new.svg" width="50px"><audio src="sttmp.mp3" controls></audio>
<a href="sttmp.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>American Anthem</b> &mdash; PySynth <b>A</b>
<br><audio src="pysynth_anthem.mp4" controls></audio>
<a href="pysynth_anthem.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>Beginning of a Chopin Nocturne</b> &mdash; PySynth <b>B</b>
<br><audio src="pysynth_chopin.mp4" controls></audio>
<a href="pysynth_chopin.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>Bach: <i>Menuet in G</i></b> &mdash; PySynth <b>S</b> &sim; <a href="menuet.abc.txt">abc source</a>
<br><audio src="menuet.mp4" controls></audio>
<a href="menuet.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b><i>The Sailor&rsquo;s Hornpipe</i></b> &mdash; PySynth <b>S</b> &sim; <a href="sailor.abc.txt">abc source</a>
<br><audio src="sailors_hornpipe.mp4" controls></audio>
<a href="sailors_hornpipe.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

</ul>

<a name="pop"></a><h3>Stereo</h3>
<ul>

<li><b>Hot Butter: <i>Popcorn</i></b> (comp. Gershon Kingsley) &mdash; 8 MIDI tracks mixed in <a href="http://www.audacityteam.org/">Audacity</a>: PySynth <b>A</b>, <b>C</b> (2x), <b>D</b>, <b>E</b>, <b>P</b>, and <b>S</b> (2x)  &sim; <a href="popcorn.txt">shell script</a>
<ul>

<li>Completely dry mix (i.e., without added effects) of PySynth output with some panning. Best for playback on e.g. tiny laptop speakers:
<br><img src="new.svg" width="50px"><audio src="popcorn.mp3" controls></audio>
<a href="popcorn.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li>This mix has some added <a href="http://calf-studio-gear.org/">Calf Reverb</a>, which gives it a more roomy sound:
<br><img src="new.svg" width="50px"><audio src="popcorn_rev.mp3" controls></audio>
<a href="popcorn_rev.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li>And finally the most processed version with four-voice Calf Multi Chorus and a big reverb. Good headphones or powerful speakers recommended:
<br><img src="new.svg" width="50px"><audio src="popcorn-multi.mp3" controls></audio>
<a href="popcorn-multi.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>
</ul>

<li><b><i>Tron Anthem</i></b> (comp. Wendy Carlos) &mdash; PySynth <b>E</b> and <b>S</b> with Calf Multi Chorus and Calf Reverb &sim; <a href="tron.txt">shell script</a>
<br><img src="new.svg" width="50px"><audio src="tron.mp3" controls></audio>
<a href="tron.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b><i>The Game is On</i></b> (from <i>Sherlock</i>, comp. Michael Price and David Arnold, arr. <a href="https://musescore.com/user/341771/scores/3545216">Sam Pigott</a>) &mdash; PySynth <b>samp</b> with Calf Multi Chorus, Calf 8-band equalizer, and Calf Reverb &sim; <a href="game.txt">shell script</a>
<br><img src="new.svg" width="50px"><audio src="game.mp3" controls></audio>
<a href="game.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b><i>The Son of Flynn</i></b> (from <i>Tron: Legacy</i>, comp. Daft Punk, arr. <a href="https://musescore.com/user/192062/scores/182502">Chris Slagell</a>) &mdash; PySynth <b>E</b>, <b>samp</b>, and <b>C</b> with several Calf effects &sim; <a href="son.txt">shell script</a>
<br><img src="new.svg" width="50px"><audio src="son.mp3" controls></audio>
<a href="son.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b><i>Doctor Who</i> Theme</b> (comp. Ron Grainer, arr. <a href="https://musescore.com/user/7008051/scores/3898256">KingFinneganZ</a>) &mdash; PySynth <b>B</b>, <b>E</b>, <b>P</b>, and <b>S</b> &sim; <a href="who.txt">shell script</a>
<br><img src="new.svg" width="50px"><audio src="dr_who.mp3" controls></audio>
<a href="dr_who.mp3"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>Bach: Invention #13, BWV 784</b> &mdash; PySynth <b>E</b> &sim; <a href="bach_invention_13.abc.txt">abc source</a>
<br><audio src="epiano.mp4" controls></audio>
<a href="epiano.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>Bach: Bourree from BWV 996</b> &mdash; PySynth <b>B</b>
<br><audio src="pysynth_bach.mp4" controls></audio>
<a href="pysynth_bach.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

<li><b>Bach: <i>Jesu, Joy of Man&rsquo;s Desiring</i></b> &mdash; PySynth <b>S</b> (treble) and <b>B</b> (bass) &sim; <a href="jesu.abc.txt">abc source</a>
<br><audio src="jesu.mp4" controls></audio>
<a href="jesu.mp4"><img src="Icons8_flat_download.svg" class="download" width="30px" alt="Download file"></a></li>

</ul>
<hr>

<img src="clipart/ENSS022D.svg" width="170px" align="left" style="padding-right: 20px;" class="hideimg">
<h2><a name="d">Download a stable release</a></h2>

<p>Here are <tt><a href="http://en.wikipedia.org/wiki/Tar_(file_format)">tar.gz</a></tt> archives of all PySynth modules:</p>

<table>
<tr>
<td><img src="clipart/ARRRIG2J.svg" width="120px"></td>
<td>&nbsp;<br>
<tt><a href="PySynth-2.4.tar.gz">PySynth-2.4.tar.gz</a></tt>&nbsp;<small>(2020-01-28; for Python 2 or 3)</small></td>
</tr>
<tr>
<td></td><td><tt><a href="PySynth-1.1.tar.gz">PySynth-1.1.tar.gz</a></tt>&nbsp;<small>(2015-01-03; final version for Python 2)</small></td>
</tr>
</table>
<h2><a name="d">Download the git version</a></h2>
<a href="https://github.com/mdoege/PySynth"><img src="GitHub_Logo.svg" width="100px" align="left" style="padding-right: 20px;"></a>
<p>You can <a href="https://github.com/mdoege/PySynth">browse the repository</a> at <a href="https://github.com/">GitHub</a> or obtain the source code with <a href="http://git-scm.com/">git</a> like this:<br>&nbsp;&nbsp;<tt>git clone git://github.com/mdoege/PySynth.git</tt></p>

<p><a href="https://github.com/mdoege/PySynth/archive/master.zip">ZIP file of the latest git version of PySynth</a></p>

<h2><a name="d">Arch Linux package (git version)</a></h2>

<p><a href="https://aur.archlinux.org/packages/python-pysynth-git/">AUR package</a>

<hr>

<img src="clipart/ENGC050D.svg" width="180px" align="left" class="hideimg">
<h2><a name="h">Changes</a></h2>

<i>2017</i>

<p><b>V2.4</b> restores Python 2 compatibility.</p>

<p><b>V2.3</b> fixes a timing bug in the MIDI file reader.</p>

<p><b>V2.2</b> adds a sample-based synth, PySynth &ldquo;samp&rdquo;, based on the <a href="http://freepats.zenvoid.org/Piano/acoustic-grand-piano.html">Salamander piano samples</a>.</p>

<p><b>V2.1</b> adds three subtractive synths: &ldquo;C&rdquo; (sawtooth wave), &ldquo;D&rdquo; (square wave), and &ldquo;P&rdquo; (white noise). Also, <tt>readmidi.py</tt> was improved to better deal with overlapping notes and notes that are switched off by setting their velocity to zero. MIDI rendering seems to work quite well now, as evidenced by the new <a href="#pop"><i>Popcorn</i> demo song</a>.</p>

<p><b>V2.0</b> switches to Python 3, adds the MIDI reader <tt>readmidi.py</tt>, and incorporates several pull requests with bug fixes and improvements.</p>

<i>2015</i>

<p><b>V1.1</b> adds the &ldquo;E&rdquo; FM synth module and <tt>mixfiles.py</tt>.</p>

<p><b>V1.0.1</b> fixes a minor issue with Pyglet sound playback and corrects the import path for PyAudio. Thanks again, Pranav!</p>

<i>2012</i>

<p><b>V1.0</b> added interactive song creation and playback via <tt>menv.py</tt>. This CLI allows you to enter notes and hear them played back as synthesized by PySynth. Thanks, Pranav!</p>

<i>2011</i>

<p><b>V0.9</b> introduced a <a href="http://cuu508.wordpress.com/2011/04/12/ringtonesynth/">Nokia ringtone synthesizer</a> module, contributed by <a href="https://github.com/cuu508">P&#275;teris Caune</a>. (Run <tt>nokiacomposer2wav.py</tt> to generate some audio samples.) Thanks, Pete!</p>

<i>2009</i>

<p><b>V0.8</b>: Improved support for ABC notation features such as tuplets and song tempo; better performance and sound of PySynth &ldquo;S&rdquo;.</p>

<p><b>V0.7</b>: Added the ABC parser and the &ldquo;B&rdquo; and &ldquo;S&rdquo; synths.</p>

<p><b>V0.6</b>: Initial public release</p>

<hr>

<img src="clipart/NOTES1.svg" width="350px" align="right">
<h2><a name="m">Synthesizer modules</a></h2>

<p>These modules take a list of notes and note lengths and use it to create a WAV file. The B, E, and S synths also require <a href="http://numpy.org/">NumPy</a>.</p>

<h3>PySynth &ldquo;A&rdquo;</h3>

<p>This additive monophonic synth is very simple and sounds vaguely like a flute or organ, combined with piano-like note volume decay. Only Python itself is needed for PySynth A. It should run on all Python-supported platforms, like Windows, Unix, and the Mac.</p>

<h3>PySynth &ldquo;B&rdquo;</h3>

<p>An additive synth module which attempts to create a more piano-like sound with more harmonics. This version is polyphonic in the sense that it doesn&rsquo;t cut off previous notes when the next note sounds.</p>

<h3>PySynth &ldquo;C&rdquo;</h3>

<p>PySynth C is a simple bowed string sound based on subtractive synthesis. It uses a sawtooth oscillator and a low-pass filter, similar to a 1970s analog synth (or a string sound in <a href="http://amsynth.github.io/">amsynth</a>, or a sound from a <a href="https://en.wikipedia.org/wiki/MOS_Technology_SID">MOS Technology SID</a>). Like PySynth A, it only requires Python itself to run.</p>

<h3>PySynth &ldquo;D&rdquo;</h3>

<p>PySynth D uses subtractive synthesis like PySynth C, but is based on a square wave instead. This synth lead-type sound is reminiscent of a woodwind. Square waves were also used in 1970s/1980s computer sound chips such as the <a href="https://en.wikipedia.org/wiki/General_Instrument_AY-3-8910">General Instrument AY-3-8910</a> or the <a href="https://en.wikipedia.org/wiki/POKEY">Atari POKEY</a>. Only Python itself is required.</p>

<h3>PySynth &ldquo;E&rdquo;</h3>

<p>Based on PySynth B, this module creates a simple e-piano sound based on phase modulation, the usual method of doing FM synthesis e.g. on 1980s Yamaha synthesizers. This sound is of course inspired by the Rhodes piano on a <a href="https://en.wikipedia.org/wiki/Yamaha_DX7">Yamaha DX7</a>.</p>

<h3>PySynth &ldquo;P&rdquo;</h3>

<p>PySynth P uses subtractive synthesis like PySynth C and D, but is based on white noise with an exponential volume envelope. It creates an untuned percussion sound. This type of sound was commonly used in the 1980s for percussive and game sound effects. Only Python itself is required.</p>

<h3>PySynth &ldquo;S&rdquo;</h3>

<p>This module simulates a single plucked string with the <a href="http://en.wikipedia.org/wiki/Karplus-Strong_string_synthesis">Karplus-Strong algorithm</a> (think guitar or harpsichord). Due to the nature of this kind of synthesis, higher frequency-notes in particular can be slightly out of tune with PySynth S, as opposed to the other variants where the harmonics are exact. This could be remedied with a higher sampling rate, but that would also make it a little slow for Python.</p>

<h3>PySynth beeper</h3>

<p>This contributed synth belongs to <tt>nokiacomposer2wav.py</tt> and is supposed to recreate ringtones of vintage Nokia feature phones.</p>

<h3>PySynth &ldquo;samp&rdquo;</h3>

<p>This synth uses the 48 kHz, 24-bit <a href="http://freepats.zenvoid.org/Piano/acoustic-grand-piano.html">Salamander piano samples</a>. Please set the path to the Salamander WAVs (including the trailing slash) on line 50.</p>

<hr>

<img src="clipart/ENBO002J.svg" width="320px" align="right">
<h2><a name="s">Controller &amp; support scripts</a></h2>

<p>These scripts serve as more convenient ways to drive the actual synthesizers.</p>

<h3>ABC parser</h3>

<p>PySynth has some basic support for music in the <a hreF="http://abcnotation.org.uk/">ABC notation language</a>. The script needs the location of the ABC song file (either local or via http), optionally followed by the song number (defaults to 1):</p>

<pre>python3 read_abc.py http://mdoege.github.io/PySynth/LiliMarlen.abc.txt</pre>

<p>&rArr; <a href="marlen.mp4">Lili Marleen.mp4</a></p>

<p>Detailed usage:</p>

<pre>read_abc.py filename [num_song] [--syn_b/--syn_c/--syn_d/--syn_e/--syn_p/--syn_s/--syn_samp]

* num_song selects the song in the file corresponding to the number given
* --syn_b, --syn_e, --syn_s, etc. can be added to use other PySynth
    modules instead of the default PySynth A</pre>

<p>If you need a quick way to edit, visualize, and&mdash;in supported browsers&mdash;play an ABC music file, take a look at <a href="http://waterpigs.co.uk/pig/">ABCPig</a>.</p>

<h3>MIDI reader</h3>

<p>Synthesize one track from a MIDI file with PySynth (defaults to MIDI track 1):</p>

<pre>python3 readmidi.py file.mid [tracknum] [file.wav] [--syn_b/--syn_c/--syn_d/--syn_e/--syn_p/--syn_s/--syn_samp]</pre>

<h3>Stereo mixer</h3>

<p><tt>mixfiles.py</tt> mixes two mono audio files to create a stereo file, e.g.: <tt>python3 mixfiles.py right.wav left.wav both.wav</tt></p>

<img src="clipart/WRONWAYJ.svg" width="120px" align="left">
<p>Please note that <tt>mixfiles.py</tt> inputs and outputs 44.1 kHz WAV files, so do not use this with Pysynth &ldquo;samp&rdquo; output (which is 48 kHz) or you will get wrong results.</p>
<br clear="all">
<h3>Interactive command line environment</h3>

<p>This feature, contributed by <a href="https://github.com/pranavrc">Pranav Ravichandran</a>, is used by running <tt>menv.py</tt>. It is really self-explaining, you enter your desired notes and any optional parameters like bpm on the command line and after you hit return PySynth synthesizes the sound and plays it back via the speakers. Depending on the speed of your computer and the length of the sound, there might be a slight pause between your input and sound playback.</p>

<p><a href="http://people.csail.mit.edu/hubert/pyaudio/">PyAudio</a> is recommended for playback functionality, but <a href="http://www.pyglet.org/">Pyglet</a>, tkSnack, or a command line audio player of your choice are also supported.</p>

<h3>Nokia ringtone synthesizer</h3>

<p><a href="https://github.com/cuu508">P&#275;teris Caune</a> has implemented <tt>nokiacomposer2wav.py</tt>, which as the name suggests takes a Nokia ringtone and synthesizes it using <tt>pysynth_beeper.py</tt>. <tt>nokiacomposer2wav.py</tt> also produces some test files when invoked directly.</p>

<hr>

<h2><a name="u">Usage</a></h2>

<p>The script can be used as a module by other Python programs or the interactive Python shell:</p>

<pre>
% <b>python3</b>
>>> <b>import pysynth</b>
>>> <b>test = ( ('c', 4), ('e', 4), ('g', 4), ('c5', 1) )</b>
>>> <b>pysynth.make_wav(test, fn = "test.wav")</b>
Writing to file test.wav
[1/4]

>>> 
</pre>
<img src="clipart/ENGC029D.svg" width="350px" align="right" class="hideimg">
<p>&hellip;which will give you <a href="test.wav">this timeless masterpiece</a>. That&rsquo;s the C major chord over the middle C followed by the high C. Three quarters, followed by a whole note (which PySynth assumes to equal 4 quarters).</p>

<p>First comes the note name (a to g), then optionally a '#' or 'b' for sharp or flat, then optionally the octave (defaults to 4). An asterisk at the end means to play the note a little louder.</p>

<p>The note duration comes next, with dotted notes represented by negative numbers (e.g. -2 is a dotted half note). 'r' is a rest. So e.g. &ldquo;The Blue Danube&rdquo; starts with:</p>

<pre>
song = (
                       ('c', 4),
  ('c*', 4), ('e', 4), ('g', 4),
  ('g*', 2), ('g5', 4),
  ('g5*', 4), ('r', 4), ('e5', 4),
  ('e5*', 4) 
)

>>> <b>from pysynth_b import *</b>
*** EXPERIMENTAL PIANO VERSION WITH NOTE CACHING ***
>>> <b>make_wav(song, fn = "danube.wav", leg_stac = .7, bpm = 180)</b> &larr; <i>Beats per minute is
                                                                          really </i>quarters<i>
                                                                          per minute here.</i>
[1/10]
[5/10]
[9/10]
Writing to file <a href="danube.wav">danube.wav</a>

>>> 
</pre>

<p>For more convenient note entry, you can e.g. use the <b>ABC notation importer</b>:</p>

<p>This is an example from the <a href="https://web.archive.org/web/20160323214714/http://trillian.mit.edu/~jc/music/abc/doc/ABCprimer.html">ABC documentation</a>:</p>

<pre>
X: 1
T: Balance the Straw
R: jig
N: This tune goes with one of the best-known Morris dances. It is also a good jig
N: for other dances, usually in AABB form. The B phrase bears a strong resemblance
N: to a certain Christmas carol, and at Morris dances you will hear words like:
N: __ Hark! the herald angels sing, __
N: __ Glory to the Morris Ring. __
N: Sometimes assorted other things are praised by the angels.
N:
M: 6/8
L: 1/8
K: G
D \
|: "G"G2B B>AB | "C"c2A A>ce | "D7"d>ed cAc | "G"G2B B2D \
|  "G"G2B B>AB | "C"c2A A>ce | "D7"d>ed cEF | "G"G4 z2 :|
B/c/ \
|: "G"dz d dz G | "(D7)"c2B "D7"B2A |  "G"dz d dz G | "D7"B2A A2D \
|  "G"G2B B>AB | "C"c2A A>ce | "D7"d>ed cEF | "G"G4 z2 :|
</pre>

<p>Creating the audio with:</p>

<pre>python3 read_abc.py straw.abc</pre>

<p>gives you <a href="straw.mp4">this file</a>.</p>

<hr>

<img src="clipart/ENGC048D.svg" width="170px" align="left" class="hideimg">
<h3><a name="l">License</a></h3>

<p>This software is provided under the <a href="http://www.gnu.org/copyleft/gpl.html">GPL</a>.</p>

<h3><a name="c">Contact</a></h3>

<p><a href="mailto:mdoege@compuserve.com?subject=PySynth"><img src="clipart/BOX004_email.svg" width="260px"></a></p>

<hr>

<img src="clipart/ENSI034D.svg" width="230px" align="right" class="hideimg">
<h3>Sample program output</h3>

<pre>
% <b>time python3 pysynth.py</b>
Piano key frequencies (for equal temperament):
Key number      Scientific name Frequency (Hz)
         1                   A0          27.50
         2                  A#0          29.14
         3                   B0          30.87
         4                   C1          32.70
         5                  C#1          34.65
         6                   D1          36.71
         7                  D#1          38.89
         8                   E1          41.20
         9                   F1          43.65
        10                  F#1          46.25
        11                   G1          49.00
        12                  G#1          51.91
        13                   A1          55.00
        14                  A#1          58.27
        15                   B1          61.74
        16                   C2          65.41
        17                  C#2          69.30
        18                   D2          73.42
        19                  D#2          77.78
        20                   E2          82.41
        21                   F2          87.31
        22                  F#2          92.50
        23                   G2          98.00
        24                  G#2         103.83
        25                   A2         110.00
        26                  A#2         116.54
        27                   B2         123.47
        28                   C3         130.81
        29                  C#3         138.59
        30                   D3         146.83
        31                  D#3         155.56
        32                   E3         164.81
        33                   F3         174.61
        34                  F#3         185.00
        35                   G3         196.00
        36                  G#3         207.65
        37                   A3         220.00
        38                  A#3         233.08
        39                   B3         246.94
        40                   C4         261.63
        41                  C#4         277.18
        42                   D4         293.66
        43                  D#4         311.13
        44                   E4         329.63
        45                   F4         349.23
        46                  F#4         369.99
        47                   G4         392.00
        48                  G#4         415.30
        49                   A4         440.00
        50                  A#4         466.16
        51                   B4         493.88
        52                   C5         523.25
        53                  C#5         554.37
        54                   D5         587.33
        55                  D#5         622.25
        56                   E5         659.26
        57                   F5         698.46
        58                  F#5         739.99
        59                   G5         783.99
        60                  G#5         830.61
        61                   A5         880.00
        62                  A#5         932.33
        63                   B5         987.77
        64                   C6        1046.50
        65                  C#6        1108.73
        66                   D6        1174.66
        67                  D#6        1244.51
        68                   E6        1318.51
        69                   F6        1396.91
        70                  F#6        1479.98
        71                   G6        1567.98
        72                  G#6        1661.22
        73                   A6        1760.00
        74                  A#6        1864.66
        75                   B6        1975.53
        76                   C7        2093.00
        77                  C#7        2217.46
        78                   D7        2349.32
        79                  D#7        2489.02
        80                   E7        2637.02
        81                   F7        2793.83
        82                  F#7        2959.96
        83                   G7        3135.96
        84                  G#7        3322.44
        85                   A7        3520.00
        86                  A#7        3729.31
        87                   B7        3951.07
        88                   C8        4186.01

Creating Demo Songs... (this might take about a minute)

Writing to file pysynth_scale.wav
[1/26]
[5/26]
[9/26]
[13/26]
[17/26]
[21/26]
[25/26]

Writing to file pysynth_anthem.wav
[1/25]
[5/25]
[9/25]
[13/25]
[17/25]
[21/25]
[25/25]

Writing to file pysynth_chopin.wav
[1/29]
[5/29]
[9/29]
[13/29]
[17/29]
[21/29]
[25/29]
[29/29]

Writing to file pysynth_bach_rh.wav
[1/52]
[5/52]
[9/52]
[13/52]
[17/52]
[21/52]
[25/52]
[29/52]
[33/52]
[37/52]
[41/52]
[45/52]
[49/52]
[1/52]
[5/52]
[9/52]
[13/52]
[17/52]
[21/52]
[25/52]
[29/52]
[33/52]
[37/52]
[41/52]
[45/52]
[49/52]

Writing to file pysynth_bach_lh.wav
[1/33]
[5/33]
[9/33]
[13/33]
[17/33]
[21/33]
[25/33]
[29/33]
[33/33]
[1/33]
[5/33]
[9/33]
[13/33]
[17/33]
[21/33]
[25/33]
[29/33]
[33/33]

Mixing files, total length 29.54 s...
0 s
5 s
10 s
15 s
20 s
25 s
63.615u 0.498s 1:06.09 96.9%    0+0k 0+45io 0pf+0w
</pre>

</body>
</html>
